package com.ydd.controller.admin;

import com.github.pagehelper.Page;
import com.ydd.dto.ArticleDTO;
import com.ydd.dto.ArticlePageDTO;
import com.ydd.entity.YddArticle;
import com.ydd.result.PageResult;
import com.ydd.result.Result;
import com.ydd.service.YddArticleService;
import com.ydd.vo.ArticleVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Description TODO
 * @Author fang
 * @Date 2023-05-29 16:47
 */
@Api(tags = "内容管理-文章管理")
@RestController
@RequestMapping("/admin/ydd_article")
@Slf4j
public class YddArticleController {
    @Autowired
    YddArticleService yddArticleService;

    /**
     * 文章列表分页
     * @param articlePageDTO
     * @return
     */
    @GetMapping("/list")
    @ApiOperation("GET文章列表分页")
    public Result<PageResult> list(ArticlePageDTO articlePageDTO){
        log.info("GET文章列表分页：{}",articlePageDTO);
        //<Page<YddArticle>
        PageResult pageResult = yddArticleService.list(articlePageDTO);

        return Result.success(pageResult);
    }

    @GetMapping("/del")
    @ApiOperation("GET文章删除")
    public Result del(String id){
        log.info("通过id删除文章:{}",id);
        yddArticleService.del(id);
        return Result.success();
    }

    @PostMapping("/add")
    @ApiOperation("POST文章添加")
    public Result add(@RequestBody  ArticleDTO articleDTO){

        log.info("新增文章:{}",articleDTO);
        yddArticleService.add(articleDTO);
        return Result.success();
    }

    /**
     * GET文章详细
     * 通过文章id查询文章详细
     * @param id
     * @return
     */
    @GetMapping("/rowInfo")
    @ApiOperation("GET文章详细")
    public Result<ArticleVO> find(Long id){
        log.info("通过id查询文章详细：{}",id);
        ArticleVO articleVO = yddArticleService.find(id);
        return Result.success(articleVO);
    }

    /**
     * POST文章修改
     * @param articleDTO
     * @return
     */
    @PostMapping("/update")
    @ApiOperation("POST文章修改")
    public Result update(@RequestBody ArticleDTO articleDTO){
        log.info("文章修改：{}",articleDTO);
        yddArticleService.update(articleDTO);
        return Result.success();
    }





}
